/*Read Yams mail whith IBrowse fixa så man kan välja bort requestern vid autoyam (ingen ibrowse startad) lägga in check att yam är igång, om inte starta kopiering av bilder till ram:t inget felmedelande om mailback.iff saknas kolla att allmail och new har olika filer?? eller kanske inte? */ OPTIONS RESULTS NL='0a'x /* newline */ NLNL='0a0a'x /* 2 newlines */ fileinc='File/s included! ' repl='Replyed! ' new='new ' fresh='fresh ' rubrik='
Here are your mail !
'||NL
/* 
 Here are your mail.'||NL */
IF ~SHOW('Ports','YAM') THEN DO
  ADDRESS 'COMMAND'
  'Run >NIL: YAM:YAM HIDE'
  'SYS:RexxC/WaitForPort YAM'
END

IF ~EXISTS('RAM:T/new.iff') THEN DO
	ADDRESS 'COMMAND'
	'copy IBrowse:Rexx/mailfile.iff ram:t/'
	'copy IBrowse:Rexx/mailfresh.iff ram:t/'
	'copy IBrowse:Rexx/mailrep.iff ram:t/'
	'copy IBrowse:Rexx/mailnew.iff ram:t/'

	IF EXISTS('IBrowse:Rexx/mailback.iff') THEN 'copy IBrowse:Rexx/mailback.iff ram:t/ >NIL:'
END

IF SHOW('Ports','IBROWSE') THEN DO
	ADDRESS YAM
	SetFolder 0

	GetFolderinfo MAX; max=RESULT
	a=0
	app=''
	linkpage='AllMail by Sören Forsberg'||rubrik
	DO WHILE a'||email||''||NL
		titel='From: '||name||'Subject: '||subject
	
		open('inputfile',file,'R')
		b=1
		list=''
		DO FOREVER
			line=readln('inputfile')
			appex=pos('application/octet-stream',line)
			IF appex~=0 then BREAK
			list=list||line||NL
			IF EOF('inputfile') THEN BREAK

		END
		close('inputfile')	
		linkpage=linkpage||''||titel||''

		if status='N' then titel=titel||fresh
		if status='N' then linkpage=linkpage||fresh
		if status='R' then titel=titel||repl
		if status='U' then titel=titel||new
		if status='R' then linkpage=linkpage||repl
		if status='U' then linkpage=linkpage||new
		if appex~=0 then titel=titel||fileinc
		if appex~=0 then linkpage=linkpage||fileinc
		linkpage=linkpage||NL 

		len=length(list)
		texttype='text/plain'
          htmlpos=pos('text/html',list)
		IF htmlpos~=0 THEN texttype='text/html'
		textpos=pos(texttype,list)
		IF textpos=0 THEN textpos=pos('X-UIDL:',list)
		startpos=pos(NLNL,list,textpos)
		out =substr(list,startpos,len-startpos)
		endpos=pos('boundary=',list)
		
		if endpos~=0 THEN DO
			outlen=LENGTH(out)
			boundary=SUBSTR(list,endpos+10,24)
			endpos=pos(boundary,out)
			endpos=lastpos(NL,out,endpos)
			out=LEFT(out,endpos)
		END
		open('outputfile','RAM:T/newmail'a'.html','W')
		line=writeln('outputfile','
'||titel)
		line=writeln('outputfile','Mail to: '||mailto)
		IF htmlpos~=0 THEN line=writeln('outputfile','
') line=writeln('outputfile',out) IF htmlpos=0 THEN line=writeln('outputfile','
') close('outputfile') a=a+1 END linkpage=linkpage||'
' open('outputfile','RAM:T/newmail.html','W') line=writeln('outputfile',linkpage) close('outputfile') ADDRESS 'IBROWSE' GOTOURL URL 'file://localhost/RAM:T/newmail.html' END IF ~SHOW('Ports','IBROWSE') THEN DO /* lägga in en requester There is new mail for you! OK! */ ADDRESS 'YAM' show setfolder 0 END exit